package com.finace.money.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.finace.money.R;
import com.finace.money.common.util.UIUtil;
import com.finace.money.data.bean.MoneyRecordBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhangpeng on 2017/11/28.
 */

public class MoneyRecordAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private ArrayList<MoneyRecordBean> mDatas;

    public void setmDatas(ArrayList<MoneyRecordBean> mDatas) {
        this.mDatas = mDatas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MoneyRecordViewHolder(LayoutInflater.
                from(UIUtil.getContext()).inflate(R.layout.item_money_record, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if(holder instanceof MoneyRecordViewHolder){

            MoneyRecordViewHolder moneyRecordViewHolder = (MoneyRecordViewHolder) holder;
            MoneyRecordBean bean = mDatas.get(position);
            moneyRecordViewHolder.ivStatusIcon.setImageResource(R.drawable.icon_success);
            if(bean.getAmount()>0){
                moneyRecordViewHolder.tvMoneyTitle.setText(R.string.money_in_sucess);
            }else {
                moneyRecordViewHolder.tvMoneyTitle.setText(R.string.money_out_sucess);
            }
            moneyRecordViewHolder.tvMoneyMoney.setText(String.valueOf(bean.getAmount()));
            moneyRecordViewHolder.tvMoneyTime.setText(bean.getDateTime());
            /*switch (position){
                case 0:
                    moneyRecordViewHolder.ivStatusIcon.setImageResource(R.drawable.icon_success);
                    break;
                case 1:
                    moneyRecordViewHolder.ivStatusIcon.setImageResource(R.drawable.icon_check);
                    break;
                case 2:
                    moneyRecordViewHolder.ivStatusIcon.setImageResource(R.drawable.icon_fail);
                    break;

            }*/
        }
    }

    @Override
    public int getItemCount() {
        return null != mDatas && mDatas.size()>0 ? mDatas.size():0;
    }

    public class MoneyRecordViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_status_icon)
        ImageView ivStatusIcon;
        @BindView(R.id.tv_money_record_title)
        TextView tvMoneyTitle;
        @BindView(R.id.tv_money_record_time)
        TextView tvMoneyTime;
        @BindView(R.id.tv_money_record_money)
        TextView tvMoneyMoney;
        public MoneyRecordViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
